package com.java.manage.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.java.common.model.Result;
import com.java.manage.dao.BrandMapper;
import com.java.manage.model.Brand;
import com.java.manage.model.Company;
import com.java.manage.service.BrandService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service
public class BrandServiceImpl implements BrandService {
    @Autowired
    private BrandMapper brandMapper;

    @Override
    public Result save(Brand brand) {
        brandMapper.save(brand);
        return Result.success();
    }
    @Override
    public Result modify(Brand brand) {
        brandMapper.modify(brand);
        return Result.success();
    }

    @Override
    public Result remove(int[] ids) {
        for (int id : ids) {
            brandMapper.remove(id);
        }
        return Result.success();
    }

    @Override
    public Result list(Brand brand) {
        PageHelper.startPage(brand.getPageNum(), brand.getPageSize());
        List<Brand> list = brandMapper.list(brand);
        PageInfo<Brand> pageInfo = new PageInfo<>(list);

        Map<String, Object> map = new HashMap<>();
        map.put("list", pageInfo.getList());
        map.put("total", pageInfo.getTotal());

        return Result.success(map);
    }

    @Override
    public Result get(int id) {
        return null;
    }

    @Override
    public Result listAll() {
        List<Brand> brands = brandMapper.listAll();
        return Result.success(brands);
    }

    @Override
    public Result brandList() {
        List<Brand> brands = brandMapper.brandList();
        return Result.success(brands);
    }
}
